/*
 * Copyright 2012 Rivoli team
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.googlecode.rivoli.integration

import org.testng.annotations.Test

class TextTest extends AluminumIntegrationTest {
	@Test
	void 'single text element should be generable'() {
		template = '''\
			@library(r: http://rivoli.googlecode.com/elements)

			@r.document
				@r.paragraph
					@r.text(value: eggs and milk)'''

		generate {}

		assert output == 'eggs and milk'
	}

	@Test
	void 'multiple text elements should be generable'() {
		template = '''\
			@library(c: http://aluminumproject.googlecode.com/core)
			@library(r: http://rivoli.googlecode.com/elements)

			@r.document
				@r.paragraph
					@c.each(elements: ${items}, element name: item)
						@r.text(value: ${item})'''

		generate {
			data['items'] = ['eggs', 'bacon']
		}

		assert output == '''\
			eggs
			bacon'''.stripIndent()
	}

	@Test
	void 'multiple paragraphs should be generable'() {
		template = '''\
			@library(r: http://rivoli.googlecode.com/elements)

			@r.document
				@r.paragraph
					@r.text(value: a paragraph)
				@r.paragraph
					@r.text(value: another paragraph)'''

		generate {}

		assert output == '''\
			a paragraph

			another paragraph'''.stripIndent()
	}

	@Test
	void 'unordered lists should be generable'() {
		template = '''\
			@library(c: http://aluminumproject.googlecode.com/core)
			@library(r: http://rivoli.googlecode.com/elements)

			@r.document
				@r.unordered list
					@c.each(elements: ${items}, element name: item)
						@r.list item
							@r.text(value: ${item})'''

		generate {
			data['items'] = ['green', 'eggs', 'ham']
		}

		assert output == '''\
			* green
			* eggs
			* ham'''.stripIndent()
	}

	@Test
	void 'ordered lists should be generable'() {
		template = '''\
			@library(c: http://aluminumproject.googlecode.com/core)
			@library(r: http://rivoli.googlecode.com/elements)

			@r.document
				@r.ordered list
					@c.each(elements: ${girls}, element name: girl)
						@r.list item
							@r.text(value: ${girl})'''

		generate {
			data['girls'] = ['alice', 'barbara', 'claire', 'denise', 'ellen', 'francis', 'geraldine', 'hilary', 'ilene', 'janine']
		}

		assert output == '''\
			 1. alice
			 2. barbara
			 3. claire
			 4. denise
			 5. ellen
			 6. francis
			 7. geraldine
			 8. hilary
			 9. ilene
			10. janine'''.stripIndent()
	}

	@Test
	void 'ordered list type should default to arabic'() {
		template = '''\
			@library(c: http://aluminumproject.googlecode.com/core)
			@library(r: http://rivoli.googlecode.com/elements)

			@r.document
				@r.ordered list
					@c.each(elements: ${presidents}, element name: president)
						@r.list item
							@r.text(value: ${president})
			'''

		generate {
			data['presidents'] = ['Washington', 'Adams', 'Jefferson']
		}

		assert output == '''\
			1. Washington
			2. Adams
			3. Jefferson'''.stripIndent()
	}

	@Test
	void 'ordered lists with alphabetic type should be generable'() {
		template = '''\
			@library(c: http://aluminumproject.googlecode.com/core)
			@library(r: http://rivoli.googlecode.com/elements)

			@r.document
				@r.ordered list(type: alphabetic)
					@c.each(elements: ${presidents}, element name: president)
						@r.list item
							@r.text(value: ${president})
			'''

		generate {
			data['presidents'] = ['Washington', 'Adams', 'Jefferson']
		}

		assert output == '''\
			a. Washington
			b. Adams
			c. Jefferson'''.stripIndent()
	}

	@Test
	void 'tables should be generable'() {
		template = '''\
			@library(r: http://rivoli.googlecode.com/elements)

			@r.document
				@r.table
					@r.row
						@r.cell
							@r.text(value: top left)
						@r.cell
							@r.text(value: top right)
					@r.row
						@r.cell
							@r.text(value: bottom left)
						@r.cell
							@r.text(value: bottom right)
			'''

			generate {}

			assert output == '''\
				+---------------------------------------+--------------------------------------+
				|top left                               |top right                             |
				+---------------------------------------+--------------------------------------+
				|bottom left                            |bottom right                          |
				+---------------------------------------+--------------------------------------+'''.stripIndent()
	}

	@Test
	void 'tables with empty cells should be generable'() {
		template = '''\
			@library(r: http://rivoli.googlecode.com/elements)

			@r.document
				@r.table
					@r.row
						@r.cell
							@r.text(value: cell)
						@r.cell
			'''

			generate {}

			assert output == '''\
				+---------------------------------------+--------------------------------------+
				|cell                                   |                                      |
				+---------------------------------------+--------------------------------------+'''.stripIndent()
	}
}